<?php

namespace maotool\core\request;

class RequestUtil
{

    /**
     * Get an item from the input data.
     * This method is used for all request verbs (GET, POST, PUT, and DELETE)
     * @param $key
     * @param $default
     * @return mixed
     */
    public static function input($key = null, $default = null)
    {
        if (isset($key)) {
            if (isset($_POST[$key])) {
                return $_POST[$key];
            }
            return $default;
        } else {
            return $_POST;
        }
    }

    public static function query($key = null, $default = null)
    {
        if (isset($key)) {
            if (isset($_GET[$key])) {
                return $_GET[$key];
            }
            return $default;
        } else {
            return $_GET;
        }
    }

    public static function post($key = null, $default = null)
    {
        if (isset($key)) {
            if (isset($_POST[$key])) {
                return $_POST[$key];
            }
            return $default;
        } else {
            return $_POST;
        }
    }

    public static function get($key = null, $default = null)
    {
        if (isset($key)) {
            if (isset($_GET[$key])) {
                return $_GET[$key];
            }
            return $default;
        } else {
            return $_GET;
        }
    }

    public static function cookie($key = null, $default = null)
    {
        if (isset($key)) {
            if (isset($_COOKIE[$key])) {
                return $_COOKIE[$key];
            }
            return $default;
        } else {
            return $_COOKIE;
        }
    }

    public static function file($key = null, $default = null)
    {

    }

    public static function has(...$keys)
    {

    }

    public static function hasAny(...$keys)
    {

    }

    public static function hasFile($key = null)
    {

    }

    public static function all()
    {
        return $_REQUEST;
    }

    public static function header($key = null, $default = null)
    {
        $headers = getallheaders();
        if (isset($key)) {
            if (isset($headers[$key])) {
                return $headers[$key];
            }
            return $default;
        } else {
            return $headers;
        }
    }

    public static function hasHeader($key = null)
    {

    }

    public static function ip()
    {

    }

}